Skip to contentSkip to conversation

Change in openvpn[master]: [TEST-ONLY] Mess with internal logic to test epoch data

Openvpn-devel plaisthos (Code Review) 1 participant 5 messages Nov 22, 2024 – Feb 16, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1732292955000.I7cdf992eb6031315c4978c6a1fbbecfa723fca91@...2715...

#1 lore raw

Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/818?usp=email

to review the following change.

Change subject: [TEST-ONLY] Mess with internal logic to test epoch data
......................................................................

[TEST-ONLY] Mess with internal logic to test epoch data

This rotates/invalidates keys extremely quickly and also jumps forward 1-8 keys instead of always one to test that part of the logic.

Change-Id I7cdf992eb6031315c4978c6a1fbbecfa723fca91

---
M src/openvpn/crypto.c
M src/openvpn/crypto_epoch.c
M tests/unit_tests/openvpn/test_ssl.c

3 files changed, 18 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/18/818/1

src/openvpn/crypto.c +3 -0
index 9166707..e990d80 100644
@@ -352,6 +352,9 @@
 int64_t
 cipher_get_aead_limits(const char *ciphername)
 {
+    /* TESTING: Make AEAD key limits really really really small to force
+     * key rollever super quickly */
+    return 256;
     if (!cipher_kt_mode_aead(ciphername))
     {
         return 0;
src/openvpn/crypto_epoch.c +14 -3
index 4a9a338..3df56ba 100644
@@ -413,8 +413,13 @@
         if (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.encrypt,
                                      opt->packet_id.send.id))
         {
-            /* Send key limit reached */
-            epoch_iterate_send_key(opt);
+            int forward = rand() % 8 + 1;
+            /* Send key limit reached, go one key forward or in this TEST
+             * gremlin mode, 1 to 8 to test the other side future key stuff */
+            for (int i = 0; i < forward; i++)
+            {
+                epoch_iterate_send_key(opt);
+            }
         }
         /* draft 8 of the aead usage limit still had but draft 9 complete
          * dropped this statement:
@@ -436,7 +441,13 @@
             /* Receive key limit reached. Increase our own send key to signal
              * that we want to use a new epoch. Peer should then also move its
              * key but is not required to do this */
-            epoch_iterate_send_key(opt);
+            int forward = rand() % 8 + 1;
+            /* gremlin mode, 1 to 8 to test the other side future key stuff */
+            for (int i = 0; i < forward; i++)
+            {
+                epoch_iterate_send_key(opt);
+            }
+
         }
     }
 
tests/unit_tests/openvpn/test_ssl.c +1 -1
index 842c944..0d4d8be 100644
@@ -398,7 +398,7 @@
         struct epoch_key e1 = { .epoch = 1, .epoch_key = { 0 }};
         memcpy(e1.epoch_key, key2.keys[0].cipher, sizeof(e1.epoch_key));
         co.flags |= CO_EPOCH_DATA_KEY_FORMAT;
-        epoch_init_key_ctx(&co, &kt, &e1, &e1, 5);
+        epoch_init_key_ctx(&co, &kt, &e1, &e1, 9);
 
         /* Do a little of dancing for the epoch_send_key_iterate to test
          * that this works too */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/818?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91
Gerrit-Change-Number: 818
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/818?usp=email

to look at the new patch set (#3).

Change subject: [TEST-ONLY] Mess with internal logic to test epoch data
......................................................................

[TEST-ONLY] Mess with internal logic to test epoch data

This rotates/invalidates keys extremely quickly and also jumps forward 1-8 keys instead of always one to test that part of the logic.

Change-Id I7cdf992eb6031315c4978c6a1fbbecfa723fca91

---
M src/openvpn/crypto.c
M src/openvpn/crypto_epoch.c
M tests/unit_tests/openvpn/test_crypto.c
M tests/unit_tests/openvpn/test_ssl.c

4 files changed, 21 insertions(+), 17 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/18/818/3

src/openvpn/crypto.c +3 -0
index 9e9fa00..3321d64 100644
@@ -352,6 +352,9 @@
 int64_t
 cipher_get_aead_limits(const char *ciphername)
 {
+    /* TESTING: Make AEAD key limits really really really small to force
+     * key rollever super quickly */
+    return 256;
     if (!cipher_kt_mode_aead(ciphername))
     {
         return 0;
src/openvpn/crypto_epoch.c +14 -3
index d69f4d5..fc687b5 100644
@@ -414,8 +414,13 @@
         if (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.encrypt,
                                      opt->packet_id.send.id))
         {
-            /* Send key limit reached */
-            epoch_iterate_send_key(opt);
+            int forward = rand() % 8 + 1;
+            /* Send key limit reached, go one key forward or in this TEST
+             * gremlin mode, 1 to 8 to test the other side future key stuff */
+            for (int i = 0; i < forward; i++)
+            {
+                epoch_iterate_send_key(opt);
+            }
         }
         /* draft 8 of the aead usage limit still had but draft 9 complete
          * dropped this statement:
@@ -437,7 +442,13 @@
             /* Receive key limit reached. Increase our own send key to signal
              * that we want to use a new epoch. Peer should then also move its
              * key but is not required to do this */
-            epoch_iterate_send_key(opt);
+            int forward = rand() % 8 + 1;
+            /* gremlin mode, 1 to 8 to test the other side future key stuff */
+            for (int i = 0; i < forward; i++)
+            {
+                epoch_iterate_send_key(opt);
+            }
+
         }
     }
 
tests/unit_tests/openvpn/test_crypto.c +3 -13
index 82ca86e..07008c2 100644
@@ -458,24 +458,14 @@
 void
 crypto_test_aead_limits(void **state)
 {
+#define BROKEN_LIMIT 0x100
     /* if ChaCha20-Poly1305 is not supported by the crypto library or in the
      * current mode (FIPS), this will still return -1 */
-    assert_int_equal(cipher_get_aead_limits("CHACHA20-POLY1305"), 0);
+    assert_int_equal(cipher_get_aead_limits("CHACHA20-POLY1305"), BROKEN_LIMIT);
 
     int64_t aeslimit = cipher_get_aead_limits("AES-128-GCM");
 
-    assert_int_equal(aeslimit, (1ull << 36) - 1);
-
-    /* Check if this matches our exception for 1600 size packets assuming
-     * AEAD_LIMIT_BLOCKSIZE (128 bits/ 16 bytes). Gives us 100 blocks
-     * + 1 for the packet */
-    int64_t L = 101;
-    /* 2 ^ 29.34, using the result here to avoid linking to libm */
-    assert_int_equal(aeslimit / L, 680390858);
-
-    /* and for 9000, 2^26.86 */
-    L = 563;
-    assert_int_equal(aeslimit / L, 122059461);
+    assert_int_equal(aeslimit, BROKEN_LIMIT);
 }
 
 void
tests/unit_tests/openvpn/test_ssl.c +1 -1
index 842c944..0d4d8be 100644
@@ -398,7 +398,7 @@
         struct epoch_key e1 = { .epoch = 1, .epoch_key = { 0 }};
         memcpy(e1.epoch_key, key2.keys[0].cipher, sizeof(e1.epoch_key));
         co.flags |= CO_EPOCH_DATA_KEY_FORMAT;
-        epoch_init_key_ctx(&co, &kt, &e1, &e1, 5);
+        epoch_init_key_ctx(&co, &kt, &e1, &e1, 9);
 
         /* Do a little of dancing for the epoch_send_key_iterate to test
          * that this works too */

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/818?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91
Gerrit-Change-Number: 818
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/818?usp=email )

Change subject: [TEST-ONLY] Mess with internal logic to test epoch data
......................................................................

Patch Set 6:

(1 comment)

Patchset:

PS6:
can we form this into some sort of unit / system test? As I read it right now it's an "internal test tool", intended to be run by you and me to see epoch keys properly rotated, but not intended for merging.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/818?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91
Gerrit-Change-Number: 818
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 29 Dec 2024 14:57:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/818?usp=email )

Change subject: [TEST-ONLY] Mess with internal logic to test epoch data
......................................................................

Patch Set 8: Code-Review-2

(1 comment)

Patchset:

PS8:
not sure if this is still needed, as we have epoch / AEAD limit unit tests now - as it is it can't go in (but never wasn't intended for "real merge" anyway)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/818?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91
Gerrit-Change-Number: 818
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 15 Feb 2025 15:43:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

plaisthos has abandoned this change. ( http://gerrit.openvpn.net/c/openvpn/+/818?usp=email )

Change subject: [TEST-ONLY] Mess with internal logic to test epoch data
......................................................................

Abandoned
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/818?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91
Gerrit-Change-Number: 818
Gerrit-PatchSet: 8
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: abandon